from sqlalchemy import create_engine, text
URL = "postgresql+psycopg://verimake:verinew@127.0.0.1:5432/metrics"
eng = create_engine(URL, future=True, pool_pre_ping=True)

try:
    with eng.begin() as c:
        c.execute(text("""
            INSERT INTO public.readings (id, username, value, ts, received_at)
            VALUES (102, 'py_test', 3.14, 1700000000, 1700000001)
        """))
        n = c.execute(text("SELECT COUNT(*) FROM public.readings")).scalar_one()
        c.execute(text("UPDATE public.readings SET value=value WHERE id=102"))
        c.execute(text("DELETE FROM public.readings WHERE id=102"))
    print("OK, table access works. rows now:", n)
except Exception as e:
    print("FAILED:", e)
